﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using RenChangYou.Common;

namespace DaoYou.Web.Guider.Account
{
    public class PageBase : System.Web.UI.Page
    {
        public PageBase()
        {
            try
            {
                CheckIsLogin();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private string _account;
        private int _uid;
        private int _type;

        private string _headImg;



        public string Account
        {
            get
            {
                if (_account == null || _account == string.Empty)
                {
                    CheckIsLogin();
                }

                return _account;
            }
        }

        public int UserType
        {
            get
            {
                if (_type == 0)
                {
                    CheckIsLogin();
                }

                return _type;
            }
        }

        public virtual void CheckIsLogin()
        {
            HttpCookie userCookie = HttpContext.Current.Request.Cookies[ConfigurationManager.AppSettings["COOKIE_KEY_USER"] as string];
            try
            {
                if (userCookie != null)
                {
                    _account = userCookie.Values["name"].ToString();
                    _type = Convert.ToInt32(userCookie.Values["type"].ToString());
                }
                else
                {
                    HttpContext.Current.Response.Redirect(string.Format("~/Account/login.aspx?ReturnUrl={0}", HttpUtility.HtmlEncode(HttpContext.Current.Request.Url.ToString())));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
